//
//  CaiZhongVC.m
//  SSC
//
//  Created by 红沙尘 on 2017/9/4.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "CaiZhongVC.h"
#import "ItemButtonView.h"
#import "ChongqingshishicaiVC.h"
#import "YinglongliangfencaiVC.h"

@interface CaiZhongVC ()<ItemButtonViewDelegate>
{
    __weak IBOutlet UITableView *mainTableView;
    
}
@end

@implementation CaiZhongVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"彩种选择"];
    self.navigationItem.leftBarButtonItem = CUSTOMVIEW([UIView new]);
}

- (void)setupUI {
    
    UIView *headerView = [[UIView alloc] init];
    
    NSArray *array = @[@{kItemTitleKey:@"重庆",kItemSubtitleKey:@"时时彩"},
                       @{kItemTitleKey:@"",kItemSubtitleKey:@"两分彩"},
                       @{kItemTitleKey:@"",kItemSubtitleKey:@"敬请期待"},
                       @{kItemTitleKey:@"",kItemSubtitleKey:@"敬请期待"},
                       @{kItemTitleKey:@"",kItemSubtitleKey:@"敬请期待"},
                       @{kItemTitleKey:@"",kItemSubtitleKey:@"敬请期待"}];
    
    int count = 2;
    CGFloat space = 10;
    CGFloat width = (ScreenWidth - (count + 1)*space)/count;
    CGFloat maxY = 0;
    
    for (int i = 0; i < array.count; i ++) {
        ItemButtonView *item = [[NSBundle mainBundle] loadNibNamed:@"ItemButtonView" owner:nil options:nil][0];
        item.frame = CGRectMake((i%count)*(width + space) + space, (i/count)*(width + space) + space, width, width);
        item.delegate = self;
        [item loadWithDict:array[i]];
        [headerView addSubview:item];
        
        maxY = MAX(maxY, CGRectGetMaxY(item.frame) + space);
    }
    
    headerView.frame = CGRectMake(0, 0, ScreenWidth, maxY);
    
    mainTableView.tableHeaderView = headerView;
}

#pragma mark - ItemButtonViewDelegate

- (void)itemButtonView:(ItemButtonView *)view atIndex:(NSInteger)index {
    
    NSString *title = [view title];
    NSString *subTitle = [view subTtile];
    
    if ([title isEqualToString:@"重庆"] && [subTitle isEqualToString:@"时时彩"]) {
        
        ChongqingshishicaiVC *vc = [[ChongqingshishicaiVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if ([title isEqualToString:@""] && [subTitle isEqualToString:@"两分彩"]) {
        YinglongliangfencaiVC *vc = [[YinglongliangfencaiVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } else {
        [MTool showMessage:@"暂未开放,敬请期待...." inView:nil];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
